package com.jx.controller.admin.content;

import com.github.pagehelper.PageInfo;
import com.jx.common.result.AjaxResult;
import com.jx.pojo.entity.content.Article;
import com.jx.pojo.entity.system.User;
import com.jx.pojo.model.content.ArticleDetail;
import com.jx.pojo.vo.content.ArticleVO;
import com.jx.pojo.vo.system.UserVO;
import com.jx.service.content.ArticleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 文章管理
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    /**
     * 分页查询文章
     */
    @GetMapping("/listPage")
    public AjaxResult listPage(ArticleVO query) {
        PageInfo<Article> page = articleService.listPage(query);
        return AjaxResult.success(page);
    }

    /**
     * 保存文章
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody ArticleDetail articleDetail) {
        articleService.saveArticle(articleDetail);
        return AjaxResult.success("保存成功");
    }

    /**
     * 删除文章
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(@RequestParam("id") Integer id) {
        articleService.deleteById(id);
        return AjaxResult.success("删除成功");
    }

    /**
     * 获取详情
     */
    @GetMapping("/getById")
    public AjaxResult getById(Integer id) {
        ArticleDetail articleDetail = articleService.getArticleById(id);
        return AjaxResult.success(articleDetail);
    }


}
